def countremainingtrees(l, m, regions):
    # Step 1: Initialize a list to represent the trees on the road
    trees = [True] * (l + 1)

    # Step 2: Remove trees in the specified regions
    for u, v in regions:
        for i in range(u, v + 1):
            trees[i] = False

    # Step 3: Count the remaining trees
    return sum(trees)

# Input reading
l, m = map(int, input().split())
regions = [tuple(map(int, input().split())) for _ in range(m)]

# Function call and output
result = countremainingtrees(l, m, regions)
print(result)
